package com.ants.project.core.utils;


import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * 短信发送接口调用短信平台进行短信发送
 * 短信平台不一样，需要根据不同平台调整代码
 * Created by liushun on 2016/6/30.
 */
public class SmsUtil {

    private static final Logger logger = LoggerFactory.getLogger(SmsUtil.class);

    //短信接口 //账号 //密码
    private static String smsApi = "", account = "", password = "";

    static {
        Properties properties = new Properties();
        //读取resources下面的配置
        InputStream is = MyDBUtil.class.getResourceAsStream("/config.properties");
        try {
            properties.load(is);
            smsApi = String.valueOf(properties.getProperty("sms.url"));
            account = String.valueOf(properties.getProperty("sms.account"));
            password = String.valueOf(properties.getProperty("sms.password"));
        } catch (IOException e) {
            logger.error("config.properties is no found !" + e.getMessage());
        }

    }


    /**
     * 发送短信
     * @param mobile 手机号码
     * @param content 模板内容
     * @return
     */
    public static Object send(String mobile, String content){
        Map data = new HashMap();
        data.put("appId", "aaf98f8953ea8e8c01540d63d18a384f");
        data.put("templateId", "79559");
        data.put("datas", "fdsf");
        data.put("to", "15673196342");
        Map map = new HashMap();
        map.put("Accept", "application/json");
        String response = HttpUtil.sendPost(smsApi, data, map, "utf-8");
        return JSON.parse(response);
    }

    public static void main(String[] args) {
        Object obj = send("15673196342", "欢迎使用犇车，您本次的验证码是{#}，请在{1}分钟内输入验证码。");
        System.out.println(obj);
    }
}
